//
// Created on 2024/11/14.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#include "capi_drag_controlability_test.h"
#include "common/common.h"
#include <arkui/drag_and_drop.h>
#include <arkui/native_gesture.h>
#include <arkui/native_interface.h>
#include <string>
#include <sstream>

namespace ArkUICApiDemo {

static void SetNodeBorderWidth(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    ArkUI_NumberValue border_value[] = {{.f32 = PARAM_2}};
    ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(rootNode, NODE_BORDER_WIDTH, &border_item);
}

static void SetNodeWidthAndHeight(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode, float width, float height)
{
    // 设置组件宽高
    ArkUI_NumberValue width_value[] = {{.f32 = width}};
    ArkUI_AttributeItem width_item = {width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(rootNode, NODE_WIDTH, &width_item);
    ArkUI_NumberValue height_value[] = {{.f32 = height}};
    ArkUI_AttributeItem height_item = {height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(rootNode, NODE_HEIGHT, &height_item);
}

static auto CreateBaseImage(ArkUI_NativeNodeAPI_1 *nodeAPI, std::string& componentId)
{
    // 创建组件并添加到容器内
    auto baseImage = nodeAPI->createNode(ARKUI_NODE_IMAGE);
    ArkUI_NumberValue width_value[] = {{.f32 = 50}};
    ArkUI_NumberValue height_value[] = {{.f32 = 50}};
    ArkUI_AttributeItem width_item = {width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue)};
    ArkUI_AttributeItem height_item = {height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(baseImage, NODE_WIDTH, &width_item);
    nodeAPI->setAttribute(baseImage, NODE_HEIGHT, &height_item);
    ArkUI_AttributeItem idStr;
    idStr.string = componentId.c_str();
    nodeAPI->setAttribute(baseImage, NODE_ID, &idStr);
    // 设置组件背景图片
    ArkUI_AttributeItem srcItem = {};
    srcItem.string = "resource://media/openeye.png";
    nodeAPI->setAttribute(baseImage, NODE_IMAGE_SRC, &srcItem);
    return baseImage;
}

static auto CreateBaseTextInput(ArkUI_NativeNodeAPI_1 *nodeAPI, std::string& componentId)
{
    // 创建组件并添加到容器内
    auto baseTextInput = nodeAPI->createNode(ARKUI_NODE_TEXT_INPUT);
    ArkUI_NumberValue width_value[] = {{.f32 = 150}};
    ArkUI_NumberValue height_value[] = {{.f32 = 50}};
    ArkUI_AttributeItem width_item = {width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue)};
    ArkUI_AttributeItem height_item = {height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(baseTextInput, NODE_WIDTH, &width_item);
    nodeAPI->setAttribute(baseTextInput, NODE_HEIGHT, &height_item);
    ArkUI_AttributeItem idStr;
    idStr.string = componentId.c_str();
    nodeAPI->setAttribute(baseTextInput, NODE_ID, &idStr);
    // 设置组件背景图片
    ArkUI_AttributeItem srcItem = {};
    srcItem.string = "abc123456";
    nodeAPI->setAttribute(baseTextInput, NODE_TEXT_INPUT_TEXT, &srcItem);
    return baseTextInput;
}

static auto CreateBaseText(ArkUI_NativeNodeAPI_1 *nodeAPI, std::string& componentId)
{
    // 创建组件并添加到容器内
    auto baseText = nodeAPI->createNode(ARKUI_NODE_TEXT);
    ArkUI_NumberValue width_value[] = {{.f32 = 150}};
    ArkUI_NumberValue height_value[] = {{.f32 = 50}};
    ArkUI_AttributeItem width_item = {width_value, sizeof(width_value) / sizeof(ArkUI_NumberValue)};
    ArkUI_AttributeItem height_item = {height_value, sizeof(height_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(baseText, NODE_WIDTH, &width_item);
    nodeAPI->setAttribute(baseText, NODE_HEIGHT, &height_item);
    ArkUI_AttributeItem idStr;
    idStr.string = componentId.c_str();
    nodeAPI->setAttribute(baseText, NODE_ID, &idStr);
    return baseText;
}

static std::vector<OH_PixelmapNative *> createPixelmap()
{
    // 设置pixelMap
    uint8_t data[960000];
    size_t dataSize = 960000;
    for (int i = 0; i < dataSize; i++) {
        data[i] = i + 1;
    }
    // 创建参数结构体实例，并设置参数
    OH_Pixelmap_InitializationOptions *createOpts;
    OH_PixelmapInitializationOptions_Create(&createOpts);
    OH_PixelmapInitializationOptions_SetWidth(createOpts, 100);
    OH_PixelmapInitializationOptions_SetHeight(createOpts, 200);
    OH_PixelmapInitializationOptions_SetPixelFormat(createOpts, PIXEL_FORMAT_BGRA_8888);
    OH_PixelmapInitializationOptions_SetAlphaType(createOpts, PIXELMAP_ALPHA_TYPE_UNKNOWN);
    // 创建Pixelmap实例
    OH_PixelmapNative *pixelmap = nullptr;
    OH_PixelmapNative_CreatePixelmap(data, dataSize, createOpts, &pixelmap);
    OH_PixelmapNative_Rotate(pixelmap, 90.0);
    OH_PixelmapNative_Opacity(pixelmap, 0.2);
    OH_PixelmapNative_Scale(pixelmap, 0.8, 1.0);
    OH_PixelmapNative_Flip(pixelmap, true, true);
    std::vector<OH_PixelmapNative *> pixelVector;
    pixelVector.push_back(pixelmap);
    return pixelVector;
}

namespace DragControlability {
static int TEST_NUM = 0;
static double forcedNumber[] = {-1, 0, 1, 5, 2147483647, 2147483648, 200.66};
static int indexA = 0;
static int indexB = 0;
static int indexC = 0;
static void OnEventReceive(ArkUI_NodeEvent *event)
{
    if (event == nullptr) {
        OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CapiDragDragaction", "OnEventReceive: event is null");
        return;
    }
    ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr;
    OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI);
	ArkUI_NodeHandle node = OH_ArkUI_NodeEvent_GetNodeHandle(event);

    auto pixelVector = createPixelmap();
    if (TEST_NUM == 90) {
        auto btDragAction = OH_ArkUI_CreateDragActionWithNode(node);
        // 设置pixelMap
        OH_ArkUI_DragAction_SetPixelMaps(btDragAction, pixelVector.data(), pixelVector.size());
        auto dragPreviewOption = OH_ArkUI_CreateDragPreviewOption();
        //设置角标数量
        auto *dragpreviewOption = OH_ArkUI_CreateDragPreviewOption();
        OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(dragpreviewOption, true);
        OH_ArkUI_DragPreviewOption_SetBadgeNumber(dragPreviewOption, forcedNumber[indexA]);
        if (indexA++ >= 6){
            indexA = 0;
        }
        OH_ArkUI_DragAction_SetDragPreviewOption(btDragAction, dragPreviewOption);
        OH_ArkUI_StartDrag(btDragAction);
        OH_ArkUI_DragAction_Dispose(btDragAction);
    }
    if (TEST_NUM == 110) {
        auto btDragAction = OH_ArkUI_CreateDragActionWithNode(node);
        // 设置pixelMap
        OH_ArkUI_DragAction_SetPixelMaps(btDragAction, pixelVector.data(), pixelVector.size());
        auto dragPreviewOption = OH_ArkUI_CreateDragPreviewOption();
        //设置角标数量
        auto *dragpreviewOption = OH_ArkUI_CreateDragPreviewOption();
        OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(dragpreviewOption, true);
        OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(dragpreviewOption, true);
        OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(dragpreviewOption, true);
        OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled(dragpreviewOption, true);
        OH_ArkUI_DragPreviewOption_SetScaleMode(dragpreviewOption, ARKUI_DRAG_PREVIEW_SCALE_AUTO);
        OH_ArkUI_DragPreviewOption_SetBadgeNumber(dragPreviewOption, forcedNumber[indexB]);
        if (indexB++ >= 6){
            indexB = 0;
        }
        OH_ArkUI_DragAction_SetDragPreviewOption(btDragAction, dragPreviewOption);
        OH_ArkUI_StartDrag(btDragAction);
        OH_ArkUI_DragAction_Dispose(btDragAction);
    }
    if (TEST_NUM == 120) {
        auto btDragAction = OH_ArkUI_CreateDragActionWithNode(node);
        auto dragPreviewOption = OH_ArkUI_CreateDragPreviewOption();
        OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "CapiDragDragaction333", "OnEventReceive: event is null");
        //设置角标数量
        auto *dragpreviewOption = OH_ArkUI_CreateDragPreviewOption();
        OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(dragpreviewOption, true);
        OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled(nullptr, true);
        OH_ArkUI_DragPreviewOption_SetBadgeNumber(dragPreviewOption, forcedNumber[indexC]);
        if (indexC++ >= 6){
            indexC = 0;
        }
        OH_ArkUI_DragAction_SetDragPreviewOption(btDragAction, dragPreviewOption);
        OH_ArkUI_StartDrag(btDragAction);
        OH_ArkUI_DragAction_Dispose(btDragAction);
    }
}
}

static auto createDragChildNode(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeType type, bool dragable)
{
    // 设置拖拽组件或数据
    auto childNode = nodeAPI->createNode(type);
    ArkUI_NumberValue border_value[] = {{.f32 = PARAM_2}};
    ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(childNode, NODE_BORDER_WIDTH, &border_item);
    nodeAPI->registerNodeEvent(childNode, NODE_ON_DRAG_START, 1, nullptr);
    nodeAPI->registerNodeEvent(childNode, NODE_ON_PRE_DRAG, 1, nullptr);
    OH_ArkUI_SetNodeDraggable(childNode, dragable);
    return childNode;
}

static auto createDragAreaNode(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeType type)
{
    // 设置组件或数据落入
    auto dragArea = nodeAPI->createNode(type);
    SetNodeWidthAndHeight(nodeAPI, dragArea, 250, 300);
    ArkUI_NumberValue border_value[] = {{.f32 = PARAM_2}};
    ArkUI_AttributeItem border_item = {border_value, sizeof(border_value) / sizeof(ArkUI_NumberValue)};
    nodeAPI->setAttribute(dragArea, NODE_BORDER_WIDTH, &border_item);
    nodeAPI->registerNodeEvent(dragArea, NODE_ON_DROP, ON_NODE_DROP, nullptr);
    nodeAPI->registerNodeEvent(dragArea, NODE_ON_DRAG_ENTER, 1, nullptr);
    nodeAPI->registerNodeEvent(dragArea, NODE_ON_DRAG_MOVE, 2, nullptr);
    nodeAPI->registerNodeEvent(dragArea, NODE_ON_DRAG_LEAVE, 3, nullptr);
    nodeAPI->registerNodeEvent(dragArea, NODE_ON_DRAG_END, 4, nullptr);
    return dragArea;
}

namespace DragControll0010 {
static void OnEventReceive(ArkUI_NodeEvent *event)
{
    if (event == nullptr) {
        OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "DragControllTest", "OnEventReceive: event is null");
        return;
    }

    ArkUI_NativeNodeAPI_1 *nodeAPI = nullptr;
    OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nodeAPI);
    auto nodeHandler = OH_ArkUI_NodeEvent_GetNodeHandle(event);
    auto nodeId = nodeAPI->getAttribute(nodeHandler, NODE_ID);

    int32_t eventId = OH_ArkUI_NodeEvent_GetTargetId(event);
    OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "DragControllTest", "OnEventReceive eventId: %{public}d",
                     eventId);
    if (eventId == ON_NODE_DROP) {
        OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "DragControllTest", "OnEventReceive: img is drag to area 1 valid");
        return;
    }
}
}

void CapiDragControlability::CreateCapiDragControlability0010(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto column2 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    std::string componentId1 = "NODE_Drag_Control_0010_IMG";
    auto img = CreateBaseImage(nodeAPI, componentId1);
    SetNodeBorderWidth(nodeAPI, column1);
    SetNodeBorderWidth(nodeAPI, column2);
    SetNodeWidthAndHeight(nodeAPI, column1, 200, 380);
    SetNodeWidthAndHeight(nodeAPI, column2, 200, 380);
    
    //设置row1不接受任何数据类型
    OH_ArkUI_DisallowNodeAnyDropDataTypes(column1);
    OH_ArkUI_SetNodeDraggable(img, true);
    std::string componentId2 = "NODE_Drag_Control_0010_ROW1";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(column1, NODE_ID, &idStr);
    nodeAPI->registerNodeEvent(img, NODE_ON_DROP, ON_NODE_DROP, nullptr);
    nodeAPI->registerNodeEventReceiver(&DragControll0010::OnEventReceive);
    nodeAPI->addChild(rootNode, img);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column1);
    nodeAPI->addChild(row, column2);
}

void CapiDragControlability::CreateCapiDragControlability0020(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto column2 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    std::string componentId1 = "NODE_Drag_Control_0020_IMG";
    auto img = CreateBaseImage(nodeAPI, componentId1);
    SetNodeBorderWidth(nodeAPI, column1);
    SetNodeBorderWidth(nodeAPI, column2);
    SetNodeWidthAndHeight(nodeAPI, column1, 200, 380);
    SetNodeWidthAndHeight(nodeAPI, column2, 200, 380);
    
    //设置row1接受text数据类型
    const char* typesArray[] = {"text"};
    OH_ArkUI_SetNodeAllowedDropDataTypes(column1, typesArray, 1);
    OH_ArkUI_SetNodeDraggable(img, true);
    std::string componentId2 = "NODE_Drag_Control_0020_ROW1";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(column1, NODE_ID, &idStr);
    nodeAPI->registerNodeEvent(img, NODE_ON_DROP, ON_NODE_DROP, nullptr);
    nodeAPI->registerNodeEventReceiver(&DragControll0010::OnEventReceive);
    nodeAPI->addChild(rootNode, img);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column1);
    nodeAPI->addChild(row, column2);
}

void CapiDragControlability::CreateCapiDragControlability0030(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column1 = nodeAPI->createNode(ARKUI_NODE_TEXT_AREA);
    auto column2 = nodeAPI->createNode(ARKUI_NODE_TEXT_AREA);
    std::string componentId1 = "NODE_Drag_Control_0030_TextInput";
    auto textInput = CreateBaseTextInput(nodeAPI, componentId1);
    SetNodeBorderWidth(nodeAPI, textInput);
    SetNodeBorderWidth(nodeAPI, column1);
    SetNodeBorderWidth(nodeAPI, column2);
    SetNodeWidthAndHeight(nodeAPI, column1, 200, 380);
    SetNodeWidthAndHeight(nodeAPI, column2, 200, 380);
    
    //设置column1接受img数据的类型
    const char* typesArray[] = {"img"};
    OH_ArkUI_SetNodeAllowedDropDataTypes(column1, typesArray, 1);
    OH_ArkUI_SetNodeDraggable(textInput, true);
    std::string componentId2 = "NODE_Drag_Control_0030_ROW1";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(column1, NODE_ID, &idStr);
    nodeAPI->registerNodeEvent(textInput, NODE_ON_DROP, ON_NODE_DROP, nullptr);
    nodeAPI->registerNodeEventReceiver(&DragControll0010::OnEventReceive);
    nodeAPI->addChild(rootNode, textInput);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column1);
    nodeAPI->addChild(row, column2);
}

void CapiDragControlability::CreateCapiDragControlability0050(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto column1 = createDragAreaNode(nodeAPI, ARKUI_NODE_TEXT_AREA);
    std::string componentId1 = "NODE_Drag_Control_0050_TextInput";
    std::string componentId2 = "NODE_Drag_Control_0050_Image";
    std::string componentId4 = "NODE_Drag_Control_0050_Text";
    auto textInput = CreateBaseTextInput(nodeAPI, componentId1);
    auto image = CreateBaseImage(nodeAPI, componentId2);
    auto text = createDragChildNode(nodeAPI, ARKUI_NODE_TEXT, true);
    
    // 设置组件背景图片
    ArkUI_AttributeItem srcItem = {};
    srcItem.string = "1234qwer";
    nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &srcItem);
    
    ArkUI_AttributeItem idStr2;
    idStr2.string = componentId4.c_str();
    nodeAPI->setAttribute(text, NODE_ID, &idStr2);
    
    SetNodeBorderWidth(nodeAPI, textInput);
    SetNodeBorderWidth(nodeAPI, column1);
    SetNodeWidthAndHeight(nodeAPI, column1, 200, 380);
    //设置可拖拽
    OH_ArkUI_SetNodeDraggable(textInput, true);
    OH_ArkUI_SetNodeDraggable(image, true);
    OH_ArkUI_SetNodeDraggable(text, true);
    auto dragAction = OH_ArkUI_CreateDragActionWithNode(image);
    auto previewOption = OH_ArkUI_CreateDragPreviewOption();
    OH_ArkUI_DragAction_SetDragPreviewOption(dragAction, previewOption);
    OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(previewOption, true);
    OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(previewOption, true);
    OH_ArkUI_SetNodeDragPreviewOption(image, previewOption);
    OH_ArkUI_DragPreviewOption_SetScaleMode(previewOption, ARKUI_DRAG_PREVIEW_SCALE_DISABLED);
    auto ret = OH_ArkUI_StartDrag(dragAction);
    OH_LOG_Print(LOG_APP, LOG_INFO, LOG_PRINT_DOMAIN, "DragControllTest", "OnEventReceive eventId: %{public}d",
                     ret);
    std::string componentId3 = "NODE_Drag_Control_0050_ROW1";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId3.c_str();
    nodeAPI->setAttribute(column1, NODE_ID, &idStr);
    OH_ArkUI_AllowNodeAllDropDataTypes(column1);
    nodeAPI->addChild(rootNode, textInput);
    nodeAPI->addChild(rootNode, image);
    nodeAPI->addChild(rootNode, text);
    nodeAPI->addChild(rootNode, column1);
}

void CapiDragControlability::CreateCapiDragControlability0090(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    
    std::string componentId2 = "NODE_Drag_Control_0090_ROW";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(row, NODE_ID, &idStr);
    
    auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    std::string componentId1 = "NODE_Drag_Control_0090_IMG";
    auto image = CreateBaseImage(nodeAPI, componentId1);
    // 设置拖拽组件或数据
    SetNodeBorderWidth(nodeAPI, image);
    nodeAPI->registerNodeEvent(image, NODE_ON_DRAG_START, 1, nullptr);
    nodeAPI->registerNodeEvent(image, NODE_ON_PRE_DRAG, 1, nullptr);
    OH_ArkUI_SetNodeDraggable(image, true);
    
    SetNodeBorderWidth(nodeAPI, column);
    SetNodeWidthAndHeight(nodeAPI, column, 200, 380);
    
    OH_ArkUI_AllowNodeAllDropDataTypes(row);
    DragControlability::TEST_NUM = 90;
    nodeAPI->registerNodeEventReceiver(&DragControlability::OnEventReceive);
    
    nodeAPI->addChild(rootNode, image);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column);
}

void CapiDragControlability::CreateCapiDragControlability0100(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    std::string componentId1 = "NODE_Drag_Control_0100_IMG";
    auto image = CreateBaseImage(nodeAPI, componentId1);
    // 设置拖拽组件或数据
    SetNodeBorderWidth(nodeAPI, image);
    nodeAPI->registerNodeEvent(image, NODE_ON_DRAG_START, 1, nullptr);
    nodeAPI->registerNodeEvent(image, NODE_ON_PRE_DRAG, 1, nullptr);
    OH_ArkUI_SetNodeDraggable(image, true);
    
    //设置角标数量
    auto *dragpreviewOption = OH_ArkUI_CreateDragPreviewOption();
    OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(dragpreviewOption, false);
    OH_ArkUI_DragPreviewOption_SetBadgeNumber(dragpreviewOption, 0);
    
    std::string componentId2 = "NODE_Drag_Control_0100_ROW";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(row, NODE_ID, &idStr);
    
    SetNodeBorderWidth(nodeAPI, column);
    SetNodeWidthAndHeight(nodeAPI, column, 200, 380);
    
    nodeAPI->addChild(rootNode, image);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column);
}

void CapiDragControlability::CreateCapiDragControlability0110(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    
    std::string componentId2 = "NODE_Drag_Control_0110_ROW";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(row, NODE_ID, &idStr);
    
    std::string componentId3 = "NODE_Drag_Control_0110_TEXT";
    auto text = CreateBaseText(nodeAPI, componentId3);
    ArkUI_AttributeItem text_item = {nullptr, 0, "hello word"};
    nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &text_item);
    
    // 设置拖拽组件或数据
    SetNodeBorderWidth(nodeAPI, text);
    nodeAPI->registerNodeEvent(text, NODE_ON_DRAG_START, 1, nullptr);
    nodeAPI->registerNodeEvent(text, NODE_ON_PRE_DRAG, 1, nullptr);
    OH_ArkUI_SetNodeDraggable(text, true);
    
    SetNodeBorderWidth(nodeAPI, column);
    SetNodeWidthAndHeight(nodeAPI, column, 200, 380);
    
    OH_ArkUI_AllowNodeAllDropDataTypes(row);
    DragControlability::TEST_NUM = 110;
    nodeAPI->registerNodeEventReceiver(&DragControlability::OnEventReceive);
    
    nodeAPI->addChild(rootNode, text);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column);
}

void CapiDragControlability::CreateCapiDragControlability0120(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    
    std::string componentId2 = "NODE_Drag_Control_0120_ROW";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(row, NODE_ID, &idStr);
    
    std::string componentId3 = "NODE_Drag_Control_0120_TEXT";
    auto text = CreateBaseText(nodeAPI, componentId3);
    ArkUI_AttributeItem text_item = {nullptr, 0, "hello word"};
    nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &text_item);
    
    // 设置拖拽组件或数据
    SetNodeBorderWidth(nodeAPI, text);
    nodeAPI->registerNodeEvent(text, NODE_ON_DRAG_START, 1, nullptr);
    nodeAPI->registerNodeEvent(text, NODE_ON_PRE_DRAG, 1, nullptr);
    OH_ArkUI_SetNodeDraggable(text, true);
    
    SetNodeBorderWidth(nodeAPI, column);
    SetNodeWidthAndHeight(nodeAPI, column, 300, 380);
    
    OH_ArkUI_AllowNodeAllDropDataTypes(row);
    DragControlability::TEST_NUM = 120;
    nodeAPI->registerNodeEventReceiver(&DragControlability::OnEventReceive);
    
    nodeAPI->addChild(rootNode, text);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column);
}

void CapiDragControlability::CreateCapiDragControlability0130(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    std::string componentId1 = "NODE_Drag_Control_0130_IMG";
    auto image = CreateBaseImage(nodeAPI, componentId1);
    // 设置拖拽组件或数据
    SetNodeBorderWidth(nodeAPI, image);
    nodeAPI->registerNodeEvent(image, NODE_ON_DRAG_START, 1, nullptr);
    nodeAPI->registerNodeEvent(image, NODE_ON_PRE_DRAG, 1, nullptr);
    OH_ArkUI_SetNodeDraggable(image, true);
    
    std::string componentId2 = "NODE_Drag_Control_0130_ROW";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(row, NODE_ID, &idStr);
    
    std::string componentId3 = "NODE_Drag_Control_0130_TEXT";
    auto text = CreateBaseText(nodeAPI, componentId3);
    ArkUI_AttributeItem text_item = {nullptr, 0, "hello word"};
    nodeAPI->setAttribute(text, NODE_TEXT_CONTENT, &text_item);
    // 设置拖拽组件或数据
    SetNodeBorderWidth(nodeAPI, text);
    nodeAPI->registerNodeEvent(text, NODE_ON_DRAG_START, 1, nullptr);
    nodeAPI->registerNodeEvent(text, NODE_ON_PRE_DRAG, 1, nullptr);
    OH_ArkUI_SetNodeDraggable(text, true);
    
    SetNodeBorderWidth(nodeAPI, column);
    SetNodeWidthAndHeight(nodeAPI, column, 200, 380);

    nodeAPI->addChild(rootNode, image);
    nodeAPI->addChild(rootNode, text);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column);
}

void CapiDragControlability::CreateCapiDragControlability0140(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto column2 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    std::string componentId1 = "DragControlAbility0140";
    auto img = CreateBaseImage(nodeAPI, componentId1);
    SetNodeBorderWidth(nodeAPI, column1);
    SetNodeBorderWidth(nodeAPI, column2);
    SetNodeWidthAndHeight(nodeAPI, column1, 200, 380);
    SetNodeWidthAndHeight(nodeAPI, column2, 200, 380);
    auto previewOption = OH_ArkUI_CreateDragPreviewOption();
    OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(previewOption, true);
    OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled(previewOption, true);
    auto dragAction = OH_ArkUI_CreateDragActionWithNode(img);
    OH_ArkUI_DragAction_SetDragPreviewOption(dragAction, previewOption);
    OH_ArkUI_DragPreviewOption_SetScaleMode(previewOption, ARKUI_DRAG_PREVIEW_SCALE_DISABLED);
    //设置row1不接受任何数据类型
    OH_ArkUI_DisallowNodeAnyDropDataTypes(column1);
    OH_ArkUI_SetNodeDraggable(img, true);
    std::string componentId2 = "NODE_Drag_Control_0140";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(column1, NODE_ID, &idStr);
    nodeAPI->registerNodeEvent(img, NODE_ON_DROP, ON_NODE_DROP, nullptr);
    nodeAPI->registerNodeEventReceiver(&DragControll0010::OnEventReceive);
    OH_ArkUI_SetNodeDragPreviewOption(img, previewOption);
    nodeAPI->addChild(rootNode, img);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column1);
    nodeAPI->addChild(row, column2);
}

void CapiDragControlability::CreateCapiDragControlability0150(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto column2 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    std::string componentId1 = "DragControlAbility0150";
    auto img = CreateBaseImage(nodeAPI, componentId1);
    SetNodeBorderWidth(nodeAPI, column1);
    SetNodeBorderWidth(nodeAPI, column2);
    SetNodeWidthAndHeight(nodeAPI, column1, 200, 380);
    SetNodeWidthAndHeight(nodeAPI, column2, 200, 380);
    auto previewOption = OH_ArkUI_CreateDragPreviewOption();
    OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(previewOption, false);
    OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(previewOption, false);
    OH_ArkUI_DragPreviewOption_SetNumberBadgeEnabled(previewOption, false);
    OH_ArkUI_DragPreviewOption_SetBadgeNumber(previewOption, 2147483647);
    //设置row1不接受任何数据类型
    OH_ArkUI_DisallowNodeAnyDropDataTypes(column1);
    OH_ArkUI_SetNodeDraggable(img, true);
    std::string componentId2 = "NODE_Drag_Control_0150";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(column1, NODE_ID, &idStr);
    nodeAPI->registerNodeEvent(img, NODE_ON_DROP, ON_NODE_DROP, nullptr);
    nodeAPI->registerNodeEventReceiver(&DragControll0010::OnEventReceive);
    OH_ArkUI_SetNodeDragPreviewOption(img, previewOption);
    nodeAPI->addChild(rootNode, img);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column1);
    nodeAPI->addChild(row, column2);
}

void CapiDragControlability::CreateCapiDragControlability0160(ArkUI_NativeNodeAPI_1 *nodeAPI, ArkUI_NodeHandle& rootNode)
{
    rootNode = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto row = nodeAPI->createNode(ARKUI_NODE_ROW);
    auto column1 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    auto column2 = nodeAPI->createNode(ARKUI_NODE_COLUMN);
    std::string componentId1 = "DragControlAbility0160";
    auto img = CreateBaseImage(nodeAPI, componentId1);
    SetNodeBorderWidth(nodeAPI, column1);
    SetNodeBorderWidth(nodeAPI, column2);
    SetNodeWidthAndHeight(nodeAPI, column1, 200, 380);
    SetNodeWidthAndHeight(nodeAPI, column2, 200, 380);
    auto previewOption = OH_ArkUI_CreateDragPreviewOption();
    OH_ArkUI_DragPreviewOption_SetDefaultShadowEnabled(previewOption, true);
    OH_ArkUI_DragPreviewOption_SetDefaultRadiusEnabled(previewOption, true);
    OH_ArkUI_DragPreviewOption_SetDefaultAnimationBeforeLiftingEnabled(previewOption, false);
    auto dragAction = OH_ArkUI_CreateDragActionWithNode(img);
    OH_ArkUI_DragAction_SetDragPreviewOption(dragAction, previewOption);
    OH_ArkUI_DragPreviewOption_SetScaleMode(previewOption, ARKUI_DRAG_PREVIEW_SCALE_AUTO);
    OH_ArkUI_DisallowNodeAnyDropDataTypes(column1);
    OH_ArkUI_SetNodeDraggable(img, true);
    std::string componentId2 = "NODE_Drag_Control_0160";
    ArkUI_AttributeItem idStr;
    idStr.string = componentId2.c_str();
    nodeAPI->setAttribute(column1, NODE_ID, &idStr);
    nodeAPI->registerNodeEvent(img, NODE_ON_DROP, ON_NODE_DROP, nullptr);
    nodeAPI->registerNodeEventReceiver(&DragControll0010::OnEventReceive);
    OH_ArkUI_SetNodeDragPreviewOption(img, previewOption);
    nodeAPI->addChild(rootNode, img);
    nodeAPI->addChild(rootNode, row);
    nodeAPI->addChild(row, column1);
    nodeAPI->addChild(row, column2);
}

} // namespace ArkUICApiDemo